import { IDisposable } from "../../Object/DisposeObject";

export enum ChannelType {
    Connect,
    Accept,
}

export class Packet {
    public readonly MinPacketSize: number = 2;
    public readonly OpcodeIndex: number = 8;
    public readonly KcpOpcodeIndex: number = 0;
    public readonly OpcodeLength: number = 2;
    public readonly ActorIdIndex: number = 0;
    public readonly ActorIdLength: number = 8;
    public readonly MessageIndex: number = 10;

    public Opcode: number;
    public ActorId: number;
    public MemoryStream: any;
}

export abstract class AChannel implements IDisposable {

    Id!: number;

    private _ChannelType!: ChannelType;
    public get ChannelType(): ChannelType {
        return this._ChannelType;
    }
    protected set ChannelType(value: ChannelType) {
        this._ChannelType = value;
    }

    private _Error!: number;
    public get Error(): number {
        return this._Error;
    }
    public set Error(value: number) {
        this._Error = value;
    }

    private _RemoteAddress!: number;
    public get RemoteAddress(): number {
        return this._RemoteAddress;
    }
    public set RemoteAddress(value: number) {
        this._RemoteAddress = value;
    }

    get IsDisposed(): boolean {
        return this.Id == 0;
    }

    public abstract Dispose(): void;

}